<?php
session_start();
header("Content-type:text/html;charset=utf-8");
$link = mysqli_connect('localhost', 'root', '123456');
mysqli_select_db($link, 'test');

if (!$link) {
    die("连接失败: " . mysqli_connect_error());
}

 $sql = "select name,password from user where name=? and password=?";
 $mysqli_stmt = $link->prepare($sql);
$name = $_POST['Username'];
$password = $_POST['Password'];
 $mysqli_stmt->bind_param('ss',$name,$password);
 $mysqli_stmt->execute();

 $result = mysqli_query($link,$sql);
 $row=mysqli_fetch_array($result,MYSQLI_BOTH);
 $number=mysqli_num_rows($result);

$sql_select = "select name,password from user where name= ?"; //从数据库查询信息
$stmt = mysqli_prepare($link, $sql_select);
mysqli_stmt_bind_param($stmt, 's', $name);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$row = mysqli_fetch_assoc($result);

if ($row) {
    echo "<script>alert('登录成功');location='Sign_in1.html'</script>";
} else {
    printf("Error: %s\n", mysqli_error($link));
    // echo "<script>alert('您输入的用户名不存在');location='Sign_in1.html'</script>".mysqli_connect_error();
    exit;
}
$mysqli_stmt->close();

?>
